package com.suao.web.controller.goods;

import com.suao.common.annotation.Log;
import com.suao.common.core.controller.BaseController;
import com.suao.common.core.domain.AjaxResult;
import com.suao.common.core.page.TableDataInfo;
import com.suao.common.enums.BusinessType;
import com.suao.common.utils.poi.ExcelUtil;
import com.suao.goods.domain.GoodsSalesInfo;
import com.suao.goods.service.IGoodsSalesInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品销售流水Controller
 *
 * @author tyz
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/goods/goodsSalesInfo")
public class GoodsSalesInfoController extends BaseController
{
    @Autowired
    private IGoodsSalesInfoService goodsSalesInfoService;

    /**
     * 查询商品销售流水列表
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsSalesInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsSalesInfo goodsSalesInfo)
    {
        startPage();
        List<GoodsSalesInfo> list = goodsSalesInfoService.selectGoodsSalesInfoList(goodsSalesInfo);
        return getDataTable(list);
    }
	@PreAuthorize("@ss.hasPermi('goods:goodsSalesInfo:listAll')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(GoodsSalesInfo goodsSalesInfo)
    {
        List<GoodsSalesInfo> list = goodsSalesInfoService.selectGoodsSalesInfoList(goodsSalesInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品销售流水列表
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsSalesInfo:export')")
    @Log(title = "商品销售流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsSalesInfo goodsSalesInfo)
    {
        List<GoodsSalesInfo> list = goodsSalesInfoService.selectGoodsSalesInfoList(goodsSalesInfo);
        ExcelUtil<GoodsSalesInfo> util = new ExcelUtil<GoodsSalesInfo>(GoodsSalesInfo.class);
        util.exportExcel(response, list, "商品销售流水数据");
    }

    /**
     * 获取商品销售流水详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsSalesInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodsSalesInfoService.selectGoodsSalesInfoById(id));
    }

    /**
     * 新增商品销售流水
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsSalesInfo:add')")
    @Log(title = "商品销售流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsSalesInfo goodsSalesInfo)
    {
        return toAjax(goodsSalesInfoService.insertGoodsSalesInfo(goodsSalesInfo));
    }

    /**
     * 修改商品销售流水
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsSalesInfo:edit')")
    @Log(title = "商品销售流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsSalesInfo goodsSalesInfo)
    {
        return toAjax(goodsSalesInfoService.updateGoodsSalesInfo(goodsSalesInfo));
    }

    /**
     * 删除商品销售流水
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsSalesInfo:remove')")
    @Log(title = "商品销售流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsSalesInfoService.deleteGoodsSalesInfoByIds(ids));
    }
}
